package cj.web.tb.controllers;

import java.util.List;
import java.util.Map;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import cj.web.login.controllers.BaseController;
import cj.web.tb.constants.PayStatusEnum;
import cj.web.tb.dao.GameDAO;
import cj.web.tb.dao.ReportCardDAO;
import cj.web.tb.domain.ReportCard;

@Path("/tBReportCard")
public class TBReportCardController extends BaseController{

	private static Logger logger = Logger.getLogger(TBReportCardController.class.getName());
	
	@Autowired
	private ReportCardDAO reportCardDao;
	@Autowired
	private GameDAO gameDao;
	
	@Get("show")
	public String showRater(Model model) {
		List<Map> gamelis =  gameDao.queryAllForEndDate();
		model.add("gamelis", gamelis);
		return "/views/tb/reportCardList.vm";
	}

	@Post("getList")
	public String queryRaterList(ReportCard reportCard) {
		//当前页  
		reportCard.setStart((reportCard.getPage()-1)*reportCard.getRows());
		reportCard.setLength(reportCard.getRows());
		
		JSONObject jo = new JSONObject();
		
		List<ReportCard> objs = reportCardDao.query(reportCard);
		List<Map> gameObj = gameDao.queryAll();
		for(ReportCard obj:objs){
			obj.setPayStatusName(PayStatusEnum.getName(obj.getPayStatus()));
			if(gameObj!=null && gameObj.size()>0){
				for(Map rep:gameObj){
					int gameId = Integer.parseInt(rep.get("id").toString());
					String gameName = rep.get("name").toString();
					if(obj.getGameId()==gameId){
						obj.setGameName(gameName);
					}
				}
			}else{
				obj.setGameName("未知");
			}
		}
		
		int size = reportCardDao.querySize(reportCard);
		
		jo.put("rows", objs);
		jo.put("total", size);
		return "@"+jo.toString();
	}
}